import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingColorChooser extends JFrame {
   private JButton bFrameBg, bLabelFg;
   private JLabel lText;
   private Container cp;
   public SwingColorChooser() {
      super("Swing ColorChooser");
      cp = getContentPane();
      lText = new JLabel("Java em Ambientes de Rede");
      cp.add("Center", lText);
      bFrameBg = new JButton("Frame Background");
      bLabelFg = new JButton("Label Foreground");
      JPanel aux = new JPanel(new GridLayout(1,2));
      aux.add(bFrameBg);
      aux.add(bLabelFg);
      cp.add("South", aux);
      bFrameBg.addActionListener(new ActionListener () {
         public void actionPerformed(ActionEvent e) {
            cp.setBackground(JColorChooser.showDialog(SwingColorChooser.this, "Frame Background",
               cp.getBackground()));
      }});
      bLabelFg.addActionListener(new ActionListener () {
         public void actionPerformed(ActionEvent e) {
            lText.setForeground(JColorChooser.showDialog(SwingColorChooser.this, "Label Background",
               lText.getForeground()));
      }});
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      pack();
   }
   public static void main(String a[]) {
      new SwingColorChooser().setVisible(true);
} }
